public class shellsort {


    public static void shellsort(int[] elem){
        int gap = elem.length;
        while (gap > 1){
            gap = gap/2;
            shell(elem,gap);
        }
    }

    public static void shell(int[] elem,int gap){
        for (int i = 1; i < elem.length; i++) {
            int tem = elem[i];
            int j = i - gap;
            for (; j >=0; j -= gap) {
                if (elem[j] > tem){
                    elem[j + gap] = elem[j];
                }else {
                    break;
                }

            }
            elem[j + gap] = tem;
        }
    }
}
